package com.azt.provider.impl;

import com.azt.api.pojo.Delivery;
import com.azt.api.service.DeliveryService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.DeliveryMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class DeliveryServiceImpl implements DeliveryService
{
    
	@Autowired
	private DeliveryMapper mapper;
    
    @Override
    public Pagination getDeliveryPage(int pageno, int pagesize, Map<String, String> searchMap)
    {
        Page<Object> startPage = PageHelper.startPage(pageno, pagesize);
		List<Delivery> list = mapper.getDeliveryByParams(searchMap);
		Pagination p = new Pagination(startPage, list);
		p.setList(list);
		p.setParams(searchMap);
        return p;
        
    }

    @Override
    public List<Delivery> findAllDelivery() {
        Example example = new Example(Delivery.class);
        example.orderBy("seq").asc();
        return mapper.selectByExample(example);
    }
    
    @Override
    public void saveDelivery(Delivery delivery)
    {
    	mapper.insert(delivery);
    }
    
    @Override
    public void deleteAllById(Integer id)
    {
    	mapper.deleteByPrimaryKey(id);
    }
    
    @Override
    public void saveEdit(Delivery delivery)
    {
    	mapper.updateByPrimaryKey(delivery);
    }
    

    @Override
    public Delivery getDeliveryById(Integer id)
    {
        return mapper.selectByPrimaryKey(id);
    }

	@Override
	public Delivery getDeliveryByName(Delivery delivery) {
		return mapper.selectOne(delivery);
	}
}
